//
//  SEGNeighbourViewModel.m
//  Commom
//
//  Created by Clavis on 2019/7/29.
//

#import "SEGNeighbourViewModel.h"
#import <Commom/SEGColorManager.h>
#import <Commom/SEGLayoutMacro.h>

@implementation SEGNeighbourViewModel
-(instancetype)init{
    if (self == [super init]) {
        _imageContent = @[];
        _widgetWidth = LYScreenWidth();
        
    }
    return self;
}
@end

/**************************SEGNeighbourViewLayout************************/
@implementation SEGNeighbourViewLayout
- (instancetype)initWithData:(SEGNeighbourViewModel *)data{
    if (self == [super init]) {
        _data = data;
    }
    [self segNeighbourViewLayout];
    return self;
}

-(void)segNeighbourViewLayout{
    //高度固定
    //    _totalHeight = KNavHeightTotal;
    
    //高度不固定
    _totalHeight = 0.1;//为零的时候布局出问题
    
    if (!_data) return;
    
    [self layout];
    
    _totalHeight += _totalImageHeight;
}

//数据处理
-(void)layout{
    if(_data.type == SEGEnumNeighbourViewType_Neighbour) {
        _imageHeight = 93.5 * kScaleWidth;
        _imagePadding = 10;
    }else {
        _imageHeight = 77.5 * kScaleWidth;
        _imagePadding = 5;
    }
    [self segImages];
}

-(void)segImages{
    CGFloat imageHeight = _imageHeight;
    CGFloat imageTotalHeight = 0;
    
    NSUInteger imageCount = _data.imageContent.count;
    if (imageCount == 0) {
        _totalImageHeight = 0;
        return;
    }
    
    if (imageCount== 1) {
        imageTotalHeight = 170 * kScaleWidth;
    }
    
    if (imageCount> 1 && imageCount <= 3) {
        imageTotalHeight = imageHeight;
    }
    if (imageCount > 3 && imageCount <= 6) {
        imageTotalHeight = imageHeight * 2 + _imagePadding;
    }
    if (imageCount > 6 && imageCount <= 9) {
        imageTotalHeight = imageHeight * 3 + _imagePadding * 2;
    }
    _totalImageHeight = imageTotalHeight + 9;
}
@end
